
package com.ukao.steward.pesenter.logistics;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.LoginBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.util.CipherUtils;
import com.ukao.steward.view.logistics.PassLoginView;

import java.util.HashMap;

import okhttp3.ResponseBody;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class PassLoginPesenter extends BasePresenter<PassLoginView> {


    public PassLoginPesenter(PassLoginView view) {
        attachView(view);
    }

    /**
     *获取签名
     */
    public void sign(     ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        addSubscription(apiStores.sign(Constant.firstParameter(mHashMap)),
                new ApiCallback<ResponseBody>() {
                    @Override
                    public void onSuccess(ResponseBody model) {

//                        if (model.getHttpCode() == 200) {
//
//                            mvpView.appSecretSucceed(model);
//                        }else{
//
//                              mvpView.showError(model.getMsg());
//                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }
                });
    }




    /**
     *登录
     */
    public void login(String  strphone,String strpassword ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("account",strphone);
        mHashMap.put("password",  CipherUtils.md5(CipherUtils.md5(strpassword)+Constant.CODES));
        addSubscription(apiStores.login(Constant.createParameter(mHashMap)),
                new ApiCallback<LoginBean>() {
                    @Override
                    public void onSuccess(LoginBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadloginSucceed(model.getData());
                        }else{
                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });
    }





}
